﻿
namespace Jayden.Dll.Web.PayPal
{
	public class PayPalPaymentLine
	{
		//https://cms.paypal.com/au/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
		private double m_Amount;
		private double m_DiscountAmount;
		private double m_DiscountAmount2;
		private double m_DiscountRate;
		private double m_DiscountRate2;
		private uint m_DiscountNum;
		private string m_ItemName;
		private string m_ItemNumber;
		private uint m_Quantity = 1;
		private double m_Shipping;
		private double m_Shipping2;
		private double m_Tax;
		private double m_TaxRate;
		private bool m_UndefinedQuantity;
		private double m_Weight;
		private string m_WeightUnit;

		public string this[string key]
		{
			get
			{
				switch(key)
				{
					case "amount" : return PayPalRequest.ToHtml(m_Amount);
					case "discount_amount": return PayPalRequest.ToHtml(m_DiscountAmount);
					case "discount_amount2": return PayPalRequest.ToHtml(m_DiscountAmount2);
					case "discount_rate": return PayPalRequest.ToHtml(m_DiscountRate);
					case "discount_rate2": return PayPalRequest.ToHtml(m_DiscountRate2);
					case "discount_num" : return m_DiscountNum != 0 ? m_DiscountNum.ToString() : null;
					case "item_name" : return m_ItemName;
					case "item_number" : return m_ItemNumber;
					case "quantity" : return m_Quantity.ToString();
					case "shipping": return PayPalRequest.ToHtml(m_Shipping);
					case "shipping2": return PayPalRequest.ToHtml(m_Shipping2);
					case "tax": return PayPalRequest.ToHtml(m_Tax);
					case "tax_rate": return PayPalRequest.ToHtml(m_TaxRate);
					case "undefined_quantity" : return m_UndefinedQuantity ? "1" : null;
					case "weight": return PayPalRequest.ToHtml(m_Weight);
					case "weight_unit" : return m_WeightUnit;
				}
				return null;
			}
			set
			{
				switch (key)
				{
					case "amount": m_Amount = PayPalRequest.FromHtml(value); break;
					case "discount_amount": m_DiscountAmount = PayPalRequest.FromHtml(value); break;
					case "discount_amount2": m_DiscountAmount2 = PayPalRequest.FromHtml(value); break;
					case "discount_rate": m_DiscountRate = PayPalRequest.FromHtml(value); break;
					case "discount_rate2": m_DiscountRate2 = PayPalRequest.FromHtml(value); break;
					case "discount_num": m_DiscountNum = uint.Parse(value); break;
					case "item_name": m_ItemName = value; break;
					case "item_number": m_ItemNumber = value; break;
					case "quantity": m_Quantity.ToString(); break;
					case "shipping": m_Shipping = PayPalRequest.FromHtml(value); break;
					case "shipping2": m_Shipping2 = PayPalRequest.FromHtml(value); break;
					case "tax": m_Tax = PayPalRequest.FromHtml(value); break;
					case "tax_rate": m_TaxRate = PayPalRequest.FromHtml(value); break;
					case "undefined_quantity": m_UndefinedQuantity = (value == "1"); break;
					case "weight": m_Weight = PayPalRequest.FromHtml(value); break;
					case "weight_unit": m_WeightUnit = value; break;
				}
			}
		}

		public double Amount { get { return m_Amount; } set { m_Amount = value; } }
		public double DiscountAmount { get { return m_DiscountAmount; } set { m_DiscountAmount = value; } }
		public double DiscountAmount2 { get { return m_DiscountAmount2; } set { m_DiscountAmount2 = value; } }
		public double DiscountRate { get { return m_DiscountRate; } set { m_DiscountRate = value; } }
		public double DiscountRate2 { get { return m_DiscountRate2; } set { m_DiscountRate2 = value; } }
		public uint DiscountNum { get { return m_DiscountNum; } set { m_DiscountNum = value; } }
		public string ItemName { get { return m_ItemName; } set { m_ItemName = value; } }
		public string ItemNumber { get { return m_ItemNumber; } set { m_ItemNumber = value; } }
		public uint Quantity { get { return m_Quantity; } set { m_Quantity = value; } }
		public double Shipping{ get { return m_Shipping; } set { m_Shipping = value; } }
		public double Shipping2{ get { return m_Shipping2; } set { m_Shipping2 = value; } }
		public double Tax{ get { return m_Tax; } set { m_Tax = value; } }
		public double TaxRate{ get { return m_TaxRate; } set { m_TaxRate = value; } }
		public bool UndefinedQuantity{ get { return m_UndefinedQuantity; } set { m_UndefinedQuantity = value; } }
		public double Weight{ get { return m_Weight; } set { m_Weight = value; } }
		public string WeightUnit{ get { return m_WeightUnit; } set { m_WeightUnit = value; } }

	}
}
